package com.flash.InventoryManagement.service.impl;

import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.mapper.SecurityStockMapper;
import com.flash.InventoryManagement.service.SecurityStockService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.sound.midi.Soundbank;
import java.sql.SQLOutput;
import java.util.HashMap;
import java.util.List;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/10
 */
@Service
public class SecurityStockServicelmpl implements SecurityStockService {
    @Autowired
    SecurityStockMapper securityStockMapper;


    @Override
    public int countSecurityStock() {
        return securityStockMapper.countSecurityStock();
    }

    @Override
    public List<SecurityStock> selectSecurityStock( SecurityStock securityStock,int page, int limit) {
        HashMap map = new HashMap();
        map.put("strWhere", buildWhere(securityStock));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return securityStockMapper.selectSecurityStock(map);
    }

    public String buildWhere (SecurityStock securityStock) {
        StringBuffer strWhere = new StringBuffer();
        if (securityStock.getSecurityStockId()!=null && !securityStock.getSecurityStockId().equals("")){
            strWhere.append(" and securityStockId like '%" + securityStock.getSecurityStockId() +"%'" );
        }
        if (securityStock.getDatestock()!=null && !securityStock.getDatestock().equals("")){
            strWhere.append(" and datestock like '%" + securityStock.getDatestock() +"%'" );
        }
        return strWhere.toString();
    }






    @Override
    public int insertSecurityStock(SecurityStock securityStock) {
        return securityStockMapper.insertSecurityStock(securityStock);
    }

    @Override
    public int deleteSecurityStock(SecurityStock securityStock) {
        return securityStockMapper.deleteSecurityStock(securityStock);
    }

    @Override
    public int updateSecurityStock(SecurityStock securityStock) {
        return securityStockMapper.updateSecurityStock(securityStock);
    }


}
